<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>柯里化函数的进一步实现</title>
</head>
<body>
    

    <script>
    
    /* +function () {
        var str1 = "ab";
        var str2 = "cd";
        str1 += str2;
        console.log(str1);

        var obj = {a: '12',b: '34'};
        obj.b += obj.a;
        console.log(obj.b);
    } (); */
    // 柯里化 函数传参进去先不执行，通过闭包的形式存起来，然后最后一次性执行。
    +function () {

        var cost = (function () {
            var args = [];
            
            return function () {
                if(arguments.length === 0){
                    var money = 0;
                    for(var i=0,len=args.length;i<len;i++){
                        money += args[i];
                    } 
                    return money;
                }else {
                    [].push.apply(args,arguments);
                }
            }
        })();
        
        cost(100);
        cost(200);
        cost(300);

        console.log(cost());
        

    } ();

    

    




    </script>
</body>
</html>